﻿var bodyDoc=GetBodyDocument();
//窗体改变大小时执行的方法
function SetCardSize()
{
    //登录页面
    var loginBackground = dojo.byId('divLoginBackground');
    if(loginBackground!=undefined && loginBackground!=null)
    {
        SetLoginCardSize(loginBackground);
    }
    else
    {
        //主页面
        var TableMasterPage = dojo.byId('TableMasterPage');
        if(TableMasterPage)
        {
            SetMasterPageSize(TableMasterPage);
        }
        else
        {
            //图表页面
            var CHARTDIV = dojo.byId('CHARTDIV');
            if(CHARTDIV)
            {
                SetChartCardSize();
            }
        }
    }
}
//调整登录窗体
function SetLoginCardSize(loginBackground)
{
    var offsetWidth= bodyDoc.documentElement.offsetWidth;
    var offsetHeight= bodyDoc.documentElement.offsetHeight;
    var rightWidth =offsetWidth;
    var rightHeight =offsetHeight;
    loginBackground.style.width=rightWidth;
    loginBackground.style.height=rightHeight;
    var scrollWidth =590;
    var scrollHeight = 435;
    
    if(rightWidth<scrollWidth)
    {
        rightWidth=scrollWidth;
    }
    if(rightHeight<scrollHeight)
    {
        rightHeight=scrollHeight;
    }
    var divLoginLocation=dojo.byId('divLoginLocation');
    if(divLoginLocation==null||divLoginLocation==undefined)
    {
        return;
    }
    if(rightWidth>1024)
    {
       loginBackground.style.left=(rightWidth-1024)/2;
       divLoginLocation.style.left=305+(rightWidth-1024)/2;
       rightWidth=1024;
    }
    else
    {
        loginBackground.style.left=0;
        divLoginLocation.style.left=305;
    }
    if(rightHeight>768)
    {
       loginBackground.style.top=(rightHeight-768)/2;
       divLoginLocation.style.top=283+(rightHeight-768)/2;
       rightHeight=768;
    }
    else
    {
       loginBackground.style.top=0;
       divLoginLocation.style.top=283;
    }
    loginBackground.style.width=rightWidth;
    loginBackground.style.height=rightHeight;
    var divCoveringBak=dojo.byId('divCoveringBak');
    if(divCoveringBak)
    {
        divCoveringBak.style.width=rightWidth>offsetWidth?rightWidth:offsetWidth;
        divCoveringBak.style.height=rightHeight>offsetHeight?rightHeight:offsetHeight;
    }
}
//调整主页
var flashMenuHeight=162;
var gridBottomSpaceHeight = 15;
var tabTopHeight=35;
var listButtonBarHeight=30;
function SetMasterPageSize(TableMasterPage)
{
    var marginLeft = bodyDoc.documentElement.offsetWidth;
    if(marginLeft>1024)
    {
        marginLeft=(marginLeft-1024)/2;
    }
    else
    {
        marginLeft=0;
    }
    TableMasterPage.style.marginLeft=marginLeft;
    
    //信息页面
    var DivInfo = dojo.byId('DivInfo'); 
    if(DivInfo)
    {
        SetInfoCardSize(DivInfo);
    }
}
//调整信息窗体
function SetInfoCardSize(DivInfo)
{
    var MiddleHeight=bodyDoc.documentElement.offsetHeight-flashMenuHeight;
    if(MiddleHeight<0)
    {
        MiddleHeight=0;
    }
    var TableMiddle=dojo.byId('TableMiddle');
    if(TableMiddle)
    {
        TableMiddle.style.height = MiddleHeight+"px";
        var TabMasterPageBody = dojo.byId('TabMasterPageBody')
        if(TabMasterPageBody)
        {
            TabMasterPageBody.style.height = MiddleHeight+"px";
            DivInfo.style.height = MiddleHeight+"px";
        
            var TabBodyContainer=dojo.byId('TabBodyContainer');
            if(TabBodyContainer)
            {
                var TabBodyHeight=MiddleHeight-tabTopHeight;
                if(TabBodyHeight<0)
                {
                    TabBodyHeight=0;
                }
                TabBodyContainer.style.height = TabBodyHeight+"px";
            }
        }
    }
    SetTreeSize();
    SetGridSize();
}
function SetGridSize()
{
    var TabGridContainer=dojo.byId('TabGridContainer');
    if(TabGridContainer)
    {
        var allHeight=bodyDoc.documentElement.offsetHeight;
        var gridHeight =allHeight-listButtonBarHeight-tabTopHeight-gridBottomSpaceHeight-flashMenuHeight;
        if(gridHeight<0)
        {
            gridHeight=0;
        }
        TabGridContainer.style.height = gridHeight+"px";
        var grid = Ext.getCmp("MVCGRID");
        if(grid)
        {
            grid.setHeight(gridHeight);
        }
    }
}
function SetTreeSize()
{
    var organTree = Ext.getCmp("CanalTree");
    if(organTree)
    {
        var allHeight=bodyDoc.documentElement.offsetHeight-flashMenuHeight;
        organTree.setHeight(allHeight);
    }
}
//调整图表窗体
function SetChartCardSize()
{
    var rightWidth = bodyDoc.documentElement.offsetWidth;
    if(rightWidth>1024)
    {
        rightWidth=(rightWidth-1024)/2;
    }
    else
    {
        rightWidth=0;
    }
    var DivChartTop=dojo.byId('divTop');
    if(DivChartTop)
    {
        DivChartTop.style.marginLeft=rightWidth;
    }
    var clientHeight=bodyDoc.documentElement.offsetHeight;
    var DivChartBottom=dojo.byId('divBottom');
    if(DivChartBottom)
    {
        DivChartBottom.style.marginLeft=rightWidth;
        DivChartBottom.style.height = clientHeight>70?clientHeight-70:0;
    }
}